<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <c:import url="common.jsp"></c:import>
    <title>帖子详情</title>
    <style type="text/css">
        #all {
        }

        #left {
            width: 800px;
            float: left;
        }

        #right {
            /*width: 200px;*/
            text-align: center;
            padding-top: 30px;
        }

        #cinfo {
            float: left;
            /*border: 1px solid #75778b;*/
            border-radius: 10px;
            width: 800px;
            height: 70px;
            background-color: #c1c3d9;
        }

        #cdelete {
            text-align: center;
            /*float: left;*/
            /*width: 200px;*/
            padding-top: 45px;
            height: 70px;

        }

        #cname {
            float: left;
            font-weight: bolder;
            width: 640px;
            height: 20px;
            color: #00bbd9;
        }

        #cdate {
            float: left;
            font-weight: bolder;
            width: 160px;
            height: 20px;
        }


        #like {
            /*text-align: center;*/
            margin-left: 500px;
            width: 60px;
            height: 60px;
        }

        .notclick {
            pointer-events: none;
        }
    </style>
</head>
<body>
<c:import url="nav.jsp"></c:import>
<div style="margin: 0 15%">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h1 class="panel-title" style="font-weight: bolder;color:#2922ff;">${invitation.title }</h1>
        </div>
        <div class="panel-body">
            <h2 class="panel-title">${invitation.summary }</h2>
        </div>
        <div class="panel-heading">
            <h4 class="panel-title">帖子内容:</h4>
        </div>
        <hr>
        <div class="panel-body">${invitation.content }</div>
    </div>

    <div style="padding-top: 30px; width: 1000px;height: 60px">

        <div id="like">
            <img src="${zts}/statics/img/a1.jpg" height="60" width="60" style="border-radius:50%">
            <div id="likenum" style="text-align: center;color: red;font-weight: bolder">${invitation.likes}</div>
        </div>
    </div>

    <div style="padding-top: 30px">
        <h4>评论信息</h4>
        <c:if test="${currentUser==null}">
            <h5 style="color: red;font-weight: bolder">请先登录!!!</h5>
        </c:if>
        <c:if test="${currentUser!=null}">
            <div id="all">
                <form action="addComment.action" method="post">
                    <div id="left">
                        <input type="hidden" id="uid" name="uid" value="${currentUser.uid}">
                        <input type="hidden" id="name" name="name" value="${currentUser.name}">
                        <input type="hidden" id="iid" name="iid" value="${invitation.id}">
                        <textarea class="form-control" rows="3" type="text" class="form-control"
                                  id="info" name="info" placeholder="请输入你的评论"></textarea>
                    </div>
                    <div id="right">
                        <button type="submit" class="btn btn-primary">SUBMIT</button>
                    </div>
                </form>
            </div>
        </c:if>
    </div>
    <c:if test="${currentUser!=null}">
        <c:forEach var="com" items="${comment }">
            <div style="padding-top: 15px">
                <tr>
                    <td>
                        <div id="cname">${com.name}</div>
                    </td>
                    <td>
                        <div id="cdate">
                            <fmt:formatDate value="${com.createdate }" pattern="yyyy-MM-dd HH:mm"></fmt:formatDate>
                        </div>
                    </td>
                </tr>
                <tr>
                    <div>
                        <div id="cinfo">${com.info}</div>
                        <c:if test="${currentUser.uid==com.uid}">
                            <div id="cdelete">
                                    <%--                                <button type="submit" class="btn btn-danger btn-sm"--%>
                                    <%--                                        value="${com.id}" id="deleteComment" onclick="deleteCom()">DELETE--%>
                                    <%--                                </button>--%>
                                <button type="submit" class="btn btn-danger btn-sm"
                                        value="${com.id}" id="deleteComment"
                                        onclick="javascript:location.href='deleteCom.action?id=${com.id }&iid=${com.iid}'">
                                    DELETE
                                </button>
                            </div>
                        </c:if>
                    </div>
                </tr>
            </div>
        </c:forEach>
    </c:if>

    <button type="button" class="btn btn-default" aria-label="Left Align">
        <span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>
    </button>
</div>

<script type="text/javascript">
    $("#like").click(function () {

        if (${currentUser==null}) {
            layer.msg("请先登录哈");
            $("#like").addClass("notclick");//设为不可点击
        }
        if (${currentUser!=null}) {
            var like = $("#likenum").text();
            console.log(like);
            var num = parseInt(like);
            $("#likenum").text(num + 1);
            $("#like").addClass("notclick");//设为不可点击

            $.post("${zts}/addLike.action", {id:${invitation.id}, num: num}, function (res) {

                layer.msg(res.true + ",请勿重复点赞哈");

            });
        }
    });


</script>
</body>
</html>